package com.tdkj.action.common;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.tdkj.model.user.BeanUserLoginLog;
import com.tdkj.service.user.IBeanUserLoginLogService;
import com.tdkj.util.PublicConfing;

public class SessionListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent arg0) {
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent arg0) {
		ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(arg0.getSession().getServletContext());
		IBeanUserLoginLogService service = ctx.getBean(IBeanUserLoginLogService.class);
		BeanUserLoginLog userLoginLog = (BeanUserLoginLog)arg0.getSession().getAttribute(PublicConfing.MEMBER_LOGIN_LOG);
		if(userLoginLog!=null){
			service.createLogoutLog(userLoginLog.getId());
		}
	}

}
